﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WindMill.Models
{
    public partial class Usuario
    {
        public static string EncodePassword(string password)
        {
            if (string.IsNullOrEmpty(password)) return "";

            var branco = "               ";
            var senhaNova = password.ToUpper().Trim() + (password.Length < 10 ? branco.Substring(0, 10 - password.Length) : "");


            int acrescimo;
            var ret = senhaNova;
            var ret2 = "";
            if (senhaNova.Length < 10)
                acrescimo = 20 - senhaNova.Length * 2;
            else
                if (senhaNova.Length > 20)
                    acrescimo = 5;
                else
                    acrescimo = 6;

            for (var i = 0; i < senhaNova.Length; i++)
            {
                ret2 = ret2 + (char)(((int)(ret[i])) + acrescimo);
                var aux = ((int)(ret2[i])).ToString("000");
                acrescimo = int.Parse(aux.Substring(2, 1)) + int.Parse(aux.Substring(1, 1));
            }
            return ret2;
        }
    }
}